//
//  NSAttributedString+Extension.swift
//  Black22
//
//  Created by Apple on 16/11/26.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

extension NSAttributedString {
    //  根据表情模型生成富文本
    class func attributedStringWithEmoticon(emoticon: HMEmoticon, font: UIFont) -> NSAttributedString {
    
        //  根据路径创建图片对象
        let image = UIImage(named: emoticon.fullPath!)
        //  根据图片对象创建文本附件
        let attachMent = HMTextAttachment()
        //  绑定对应的表情模型
        attachMent.emoticon = emoticon
        attachMent.image = image
        let lineHeight = font.lineHeight
        //  设置图片大小
        attachMent.bounds = CGRect(origin: CGPoint(x: 0, y: -3.5), size: CGSize(width: lineHeight, height: lineHeight))
        //  根据文本附件创建富文本
        let attributedStr = NSAttributedString(attachment: attachMent)

        return attributedStr
    }
    
    
    
}
